# pylint: disable-msg=E1101
"""
@author: Sergiy Tsymbalyuk
"""

import logging

from pylons import tmpl_context as c, request
from pylons.i18n import lazy_ugettext as _
from pylons.controllers.util import abort

from repoze.what.plugins.pylonshq import ControllerProtector
from repoze.what.predicates import in_group

from chowa.model.organization import District
from hrms.lib.base import BaseController, render, Session
from hrms.lib.dberrors import get_errors

log = logging.getLogger(__name__)

@ControllerProtector(in_group('hrms.administrators'))
class DberrorsController(BaseController):
    def index(self, id=None):
        if id:
            c.district = Session.query(District).get(id)
        else:
            c.district = Session.query(District).filter_by(is_primary=True).one()
            if not c.district:
                return abort(404)
        c.errors = get_errors(c.district.id)
        return render('/hrms/dberrors/index.html')
    